package noneed;

import java.util.HashMap;



public class Commands {
		

	
	public interface Command {
			
			public boolean execute(String cmd);
	
			public String getKey();
	}
	
	public class TagCommands implements Command  {
		
		public boolean execute(String cmd){ return true;}

		public String getKey(){return "TagCommands";}

	}
	
	public class FileCommands implements Command  {
		
		public boolean execute(String cmd){ return true;}

		public String getKey(){return "FileCommands";}
	}
	public class TrackingCommands implements Command  {
		
		public boolean execute(String cmd){ return true;}

		public String getKey(){return "TrackingCommands";}
	}
	
	public class logCommands implements Command  {
		
		public boolean execute(String cmd){ return true;}

		public String getKey(){return "logCommands";}
	}
	
	public class OptionsCommands implements Command  {
		
		public boolean execute(String cmd){ return true;}

		public String getKey(){return "OptionsCommands";}
	}
	
	
	//an HashMap of all the commands
	private HashMap<String, Command> commandsMap;
	
	//a function that add to the HashMap
	private void add(Command c) {
		commandsMap.put(c.getKey(), c);

	}
	
	//Ctor of Commands
	public Commands() {
		//init commandsMap
		commandsMap = new HashMap<String, Command>();
		//add to hashMap
		add(new TagCommands());
		add(new FileCommands());
		add(new TrackingCommands());
		add(new logCommands());
		add(new OptionsCommands());
	}
	
	private String firstword(String cmd) {

		String words[] = cmd.split(" ");
		return words[0];
	}
	
	private String secondword(String cmd) {

		String words[] = cmd.split(" ");
		return words[1];
	}
	
	public void runCommand(String cmd) {
		try{
			if (commandsMap.get(firstword(cmd)) == null)// || !(commandsMap.get(firstword(cmd))).execute(cmd))
				System.out.println("Error: command not found.");
			
			else
			{
				Command cmnd=commandsMap.get(firstword(cmd));
				
				
			}
		}
		catch(Exception e)
		{
			System.out.println("Error: command not found.");
		}

	}
	
}
